package models

import (
	"github.com/astaxie/beego"
	"github.com/astaxie/beego/orm"
	_ "github.com/go-sql-driver/mysql"
	"time"
)

type IpccFileInfo struct {
	Id         int
	FileId     string
	FileName   string
	Path       string
	Describe   string
	CreateTime time.Time
	Appid      string
	Active     int
}

func InsertNewFile(fileId, name, path, describ, appid string) bool {

	newFile := IpccFileInfo{
		Appid:      appid,
		FileId:     fileId,
		FileName:   name,
		Path:       path,
		Describe:   describ,
		Active:     1,
		CreateTime: time.Now(),
	}

	o := orm.NewOrm()
	o.Using("default")

	num, err := o.Insert(&newFile)
	if num == 0 || err != nil {
		beego.Debug("insert to sql failed:%v,appid:%v,fileName:%v", err, appid, name)
		return false
	}

	return true
}

func RegFile() {
	orm.RegisterModel(new(IpccFileInfo))
}
